//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////

class Main extends egret.DisplayObjectContainer {



    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
    }

    private onAddToStage(event: egret.Event) {

        egret.lifecycle.addLifecycleListener((context) => {
            // custom lifecycle plugin

            context.onUpdate = () => {

            }
        })

        egret.lifecycle.onPause = () => {
            egret.ticker.pause();
        }

        egret.lifecycle.onResume = () => {
            egret.ticker.resume();
        }

        this.runGame().catch(e => {
            console.log(e);
        })



    }

    private async runGame() {
        await this.loadResource()
        this.createGameScene();
        // const result = await RES.getResAsync("description_json")
        // this.startAnimation(result);
        await platform.login();
        const userInfo = await platform.getUserInfo();
        console.log(userInfo);

    }

    private async loadResource() {
        try {
            const loadingView = new LoadingUI();
            this.stage.addChild(loadingView);
            await RES.loadConfig("resource/default.res.json", "resource/");
            await RES.loadGroup("preload", 0, loadingView);
            this.stage.removeChild(loadingView);
        }
        catch (e) {
            console.error(e);
        }
    }

    private textfield: egret.TextField;

    /**
     * 创建游戏场景
     * Create a game scene
     */
    private createGameScene() {
    let txt:egret.TextField=new egret.TextField();
    txt.text="姓名:";
    txt.size=50;
    txt.y=100;
    txt.x=20;
    this.addChild(txt);

    let txt1:egret.TextField=new egret.TextField();
    txt1.type=egret.TextFieldType.INPUT;
    txt1.width=400;
    txt1.height=50;
    txt1.border=true;
    txt1.borderColor=0xff0000
    txt1.y=100;
    txt1.x=150;
    txt1.size=50;
    txt1.textAlign=egret.HorizontalAlign.CENTER;
    txt1.verticalAlign=egret.VerticalAlign.MIDDLE;
    this.addChild(txt1);

    let txt2:egret.TextField=new egret.TextField();
    txt2.text="电话:";
    txt2.size=50;
    txt2.y=200;
    txt2.x=20;
    this.addChild(txt2);

    let txt3:egret.TextField=new egret.TextField();
    txt3.type=egret.TextFieldType.INPUT;
    txt3.inputType=egret.TextFieldInputType.TEL;
    txt3.width=400;
    txt3.height=50;
    txt3.size=50;
    txt3.border=true;
    txt3.borderColor=0xff0000
    txt3.y=200;
    txt3.x=150;
     txt3.textAlign=egret.HorizontalAlign.CENTER;
    txt3.verticalAlign=egret.VerticalAlign.MIDDLE;
    this.addChild(txt3);

    let txt4:egret.TextField=new egret.TextField();
    txt4.text="确认";
    txt4.size=50;
    txt4.width=200
    txt4.height=80
    txt4.y=400;
    txt4.x=300;
    txt4.border=true;
    txt4.textAlign=egret.HorizontalAlign.CENTER;
    txt4.verticalAlign=egret.VerticalAlign.MIDDLE;
    txt4.borderColor=0x000000;
    txt4.background=true;
    txt4.backgroundColor=0x0000ff;
    this.addChild(txt4);
    txt4.touchEnabled=true;
    txt4.addEventListener(egret.TouchEvent.TOUCH_TAP,myfunction,this)
  
    function myfunction(){
        juxing.textFlow=<egret.ITextElement[]>[
            {text:txt1.text,style:{textColor:0xff0000,size:50}},
            {text:'你的手机号码是：\n',style:{textColor:0x0000ff}},
            {text:txt3.text,style:{textColor:0xb7179c,size:50}},
        ]
    }

    let juxing:egret.TextField=new egret.TextField();
    juxing.border=true;
    juxing.borderColor=0x000000;
    juxing.width=600;
    juxing.height=300;
    juxing.x=20;
    juxing.y=600;
    juxing.textAlign=egret.HorizontalAlign.CENTER;
    this.addChild(juxing);
    }
}